import { createStore } from "vuex"
import { doSignin } from "api"

export default createStore({
  modules:{},
  state:{
    token:false,
    uinfo:{},
    database:0
  },
  getters:{
    token: state => state.token,
    uinfo: state => state.uinfo,
    database: state => state.database,
  },
  mutations:{
    SET_TOKEN: (state,token) => state.token = token,
    SET_UINFO: (state,uinfo) => state.uinfo = uinfo,
    SET_DATABASE: (state,studata) => state.database = studata,
  },
  actions:{
    logIn:async ({commit},data) => {
      const { token,type,id } = await doSignin(data)
      console.log({type})
      commit('SET_TOKEN',{ token,id })
      commit('SET_UINFO',{
        ava:'https://cdn.seovx.com/?mom=302',
      })
    },
    logOut:async ({commit}) => {
      commit('SET_TOKEN',null)
      commit('SET_UINFO',{})
    }
  }
})
